<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <link rel="icon" href="<%= BASE_URL %>favicon.ico">
    <title>
        <%= htmlWebpackPlugin.options.title %>
    </title>
    <style>
        .text-popup {
            animation: textPopup 1s;
            color: red;
            user-select: none;
            white-space: nowrap;
            position: absolute;
            z-index: 99;
        }

        @keyframes textPopup {

            0%,
            100% {
                opacity: 0;
            }

            5% {
                opacity: 1;
            }

            100% {
                transform: translateY(-50px);
            }
        }
    </style>


</head>

<body>

    <noscript>
        <strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled.
                Please enable it to continue.</strong>
    </noscript>
    <div id="app">


    </div>
</body>

</html>

<script type="text/javascript" src="sketch.js"></script>
<script src="script.js" defer></script>
<script>
    var fnTextPopup = function (arr, options) {
        // arr参数是必须的
        if (!arr || !arr.length) {
            return;
        }
        // 主逻辑
        var index = 0;
        document.documentElement.addEventListener('click', function (event) {
            var x = event.pageX, y = event.pageY;
            var eleText = document.createElement('span');
            eleText.className = 'text-popup';
            this.appendChild(eleText);
            if (arr[index]) {
                eleText.innerHTML = arr[index];
            } else {
                index = 0;
                eleText.innerHTML = arr[0];
            }
            // 动画结束后删除自己
            eleText.addEventListener('animationend', function () {
                eleText.parentNode.removeChild(eleText);
            });
            // 位置
            eleText.style.left = (x - eleText.clientWidth / 2) + 'px';
            eleText.style.top = (y - eleText.clientHeight) + 'px';
            // index递增
            index++;
        });
    };

    fnTextPopup(['好好学习', '天天向上']);
</script>